import { Component , ChangeDetectorRef} from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

import {HttpService} from '../../providers/HttpService';
import { APP_YUANCHNEG_URL } from '../../providers/Constants';
declare let cordova: any;
/**
 * Generated class for the EquipmentPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-equipment',
  templateUrl: 'equipment.html',
})
export class EquipmentPage {

  constructor(public navCtrl: NavController, private httpService: HttpService,public navParams: NavParams,public cd: ChangeDetectorRef) {
    this.token=this.navParams.data.value.login_token;
  }
  str1='';
  str2='';
  S2='';
 token:any;
all_one=true;
alltext=false;
deviceName='';//设备名称
ProjectNum='';//项目编号
ScreeningNum='';//筛选号
oHeight='';
oWeight='';
all_equip=false;//设备按钮
InstrumentData=false;//设备信息
all_equipONE=true;
isBMI='';
oPressure=false;
diastolic='';//舒张压
systolic='';//收缩压
pulse='';//脉搏
oName='';//姓名
IDcard=false;
IDID='';
SXcard=false;
TIME='';
consent=false;
CID='';
PID='';

statee: string = './assets/imgs/start.png';
  ionViewDidLoad() {
    console.log('ionViewDidLoad EquipmentPage');
  }
  all(){
    cordova.plugins.test.star(result=>{
        this.str1=result;
        var obj={
              code:this.str1,
              login_token:this.token
          }
            this.httpService.post(APP_YUANCHNEG_URL+'/api/pt/qrBarCodeValide/getMessage',obj).then(res=>{
                              
                             if(res.code=="111"){
                                this.oHeight='';
                                this.oWeight='';
                                this.deviceName='';//设备名称
                                 this.ProjectNum=res.value.pnum;
                                 this.ScreeningNum=res.value.subnum;
                                 this.oName=res.value.name;
                                 this.InstrumentData=false;
                                 this.all_one=false;
                                 this.all_equip=true;
                                 this.SXcard=true;
                                 this.isBMI='';
                                 this.diastolic='';
                                 this.systolic='';
                                 this.pulse='';
                                 this.IDID='';
                                 this.consent=false;
                                 this.alltext=true;
                                  this.cd.detectChanges();  
                             }else if(res.code=="222"){
                                  this.oHeight='';
                                this.oWeight='';
                                this.deviceName='';//设备名称
                                this.isBMI='';
                                 this.diastolic='';
                                 this.systolic='';
                                 this.pulse='';
                                 this.IDID=res.value.cardid;
                                 this.oName=res.value.name;
                                  this.ProjectNum=res.value.pnum;
                                  this.SXcard=false;
                               this.all_one=false;
                               this.CID=res.value.cid;
                               this.PID=res.value.pid;
                               this.consent=true;
                                 this.InstrumentData=false;
                                 this.IDcard=true;

                               this.alltext=true;
                                  this.cd.detectChanges(); 
                             }else{
                                alert(res.msg);
                             }
                            
                              
                           })
            
    },error=>console.log(error));
  } 
//设备扫描
  mentSca(){
    cordova.plugins.test.star(result=>{
        this.str2=result;
        this.S2=this.str2.substr(0, 1);

        var obj={
              id:this.str1,
              hardware:this.str2,
              login_token:this.token
          }
          if(this.S2=="H"){//身高体重
        
                this.httpService.post(APP_YUANCHNEG_URL+'/api/pt/qrBarCodeValide/addMessageH',obj).then(res=>{
                                      
                                     if(res.code=="111"){
                                         
                                         this.oWeight=res.value.weight;
                                         this.oHeight=res.value.height;
                                         this.deviceName=res.value.sname;
                                         this.isBMI=res.value.bmi;
                                         this.TIME=res.value.time;
                                         this.all_equipONE=false;
                                         this.InstrumentData=true;
                                          this.cd.detectChanges();
                                     }else{
                                          alert(res.msg);
                                     }
                                    
                                      
                                   })
          }else if(this.S2=="X"){//血压
                 
              
                 this.httpService.post(APP_YUANCHNEG_URL+'/api/pt/qrBarCodeValide/addMessageX',obj).then(res=>{
                                      
                                     if(res.code=="111"){
                                      
                                         this.diastolic=res.value.diastolic;
                                         this.systolic=res.value.systolic;
                                         this.TIME=res.value.time;
                                         this.pulse=res.value.pulse;
                                         this.deviceName=res.value.sname;
                                         this.all_equipONE=false;
                                         this.oPressure=true;
                                          this.cd.detectChanges();

                                     }else{
                                          alert(res.msg);
                                     }
                                    
                                      
                                   })
                
          }else{
            alert("请正确扫描");
          }



    },error=>console.log(error));

  }
  //同意知情
consentCli(){
var obj={
              cid:this.CID,
              pid:this.PID,
              login_token:this.token
          }
  this.httpService.post(APP_YUANCHNEG_URL+'/api/pt/candidateSubjects/getCoding',obj).then(res=>{
                                      
                   if(res.code=="111"){
                          alert(res.msg);
                       this.all_one=true;
                      this.alltext=false;
                      this.all_equipONE=true;
                      this.deviceName='';//设备名称
                      this.ProjectNum='';//项目编号
                      this.ScreeningNum='';//筛选号
                      this.oHeight='';
                      this.oWeight='';
                      this.CID='';
                               this.PID='';

                      this.all_equip=false;//设备按钮
                       this.str1='';
                          this.S2='';
                          this.isBMI='';  
                          this.diastolic='';
                       this.systolic='';
                       this.pulse='';    
                       this.oName='';//姓名
                      this.IDcard=false;
                      this.IDID='';
                      this.SXcard=false;
                      this.consent=false;
                      this.oPressure=false; 
                      this.InstrumentData=false;//设备信息
                        this.cd.detectChanges();

                   }else{
                        alert(res.msg);
                   }
                  
                    
                 })
}

  //重置 
  reset(){
        this.all_one=true;
        this.alltext=false;
        this.all_equipONE=true;
        this.deviceName='';//设备名称
        this.ProjectNum='';//项目编号
        this.ScreeningNum='';//筛选号
        this.oHeight='';
        this.oWeight='';
        this.CID='';
        this.all_equip=false;//设备按钮
         this.str1='';
            this.S2='';
            this.isBMI='';  
            this.diastolic='';
         this.systolic='';
         this.pulse='';    
         this.oName='';//姓名
        this.IDcard=false;
        this.IDID='';
        this.PID='';
        this.SXcard=false;
        this.consent=false;
        this.oPressure=false; 
        this.InstrumentData=false;//设备信息
        this.cd.detectChanges();
  }

}
